import React, { Component } from 'react'
import './index.css';
import axios from 'axios';

export default class YiYan extends Component {
    state = {
        text: ''
    }
    render() {
        return (
            <div className="yiyan-container">
                <div className="mask"></div>
                <div className="text">
                    {this.state.text}
                </div>
            </div>
        )
    }

    componentDidMount(){
        this.timer = setInterval(() => {
            this.send();
        }, 5000);
        this.send();
    }

    componentWillUnmount(){
        clearInterval(this.timer);
    }

    send = async () => {
        let result = await axios('https://v1.hitokoto.cn/');
        this.setState({
            text: result.data.hitokoto
        })
    }
}
